$(function() {
	//初始化
	Begin();
})
var thisTabNum = "0";
var passwordFirst = "";
//邮箱验证正则表达式
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
var rootOrgSet = new Vue({
	el: "#rootOrgSet",
	data: function() {
		//自定义验证，验证机构编码
		var orgName = function(rule, value, callback) {
			if(!value) {
				return callback(new Error('请输入组织机构名称'));
			}
			return callback();
		};
		var userAccount = function(rule, value, callback) {
			if(!value) {
				return callback(new Error('请输入管理员账号'));
			}
			return callback();
		};
		var userPassword = function(rule, value, callback) {
			passwordFirst = value;
			if(!value) {
				return callback(new Error('请输入管理员密码'));
			}
			return callback();
		};
		var userPassword1 = function(rule, value, callback) {
			if(!value) {
				return callback(new Error('请确认管理员密码'));
			}
			if(passwordFirst!=value){
				return callback(new Error('两次输入密码不一致'));
			}
			return callback();
		};
		var userEmail = function(rule, value, callback) {
			if(!value) {
				return callback(new Error('请输入管理员邮箱'));
			}
			if(!myreg.test(value)){
				return callback(new Error('邮箱格式不正确'));
			}
			return callback();
		};
		return {
			initForm: {
				remnantInput: 0,
				orgName: '',
				userAccount: '',
				userPassword: '',
				userPassword1: '',
				userEmail: ''
			},
			rules: {
				orgName: [{
					required: true,
					validator: orgName,
					trigger: 'blur'
				}],
				userAccount: [{
					required: true,
					validator: userAccount,
					trigger: 'blur'
				}],
				userPassword: [{
					required: true,
					validator: userPassword,
					trigger: 'blur'
				}],
				userPassword1: [{
					required: true,
					validator: userPassword1,
					trigger: 'blur'
				}],
				userEmail: [{
					required: true,
					validator: userEmail,
					trigger: 'blur'
				}],
			},
			dialogVisible: false,
			dialogVisibleLogin:false
		}
	},
	methods: {
		handleClick: function(tab, event) {
			thisTabNum = tab.index;
		},
		descInput: function() {
			this.initForm.remnantInput = this.initForm.orgName.length;
		},
		submitForm: function(formName) {
			this.$refs["initForm"].validate(function(valid) {
				if(!valid) {
					return false;
				} else {
					rootOrgSet.dialogVisible = true;
				}
			});
			
		},
		tijiao:function(obj) {
			this.dialogVisible = false;
			var self = this;
			if(obj) {
				var url = "/system/init/initSys";
				VanyAjax(url, self.initForm).done(function(data) {
					location.href = sessionStorage.loginUrl;
					$.ajax({
						url: "/logout",
						method: "GET",
						async: false,
						data: {
							"token": sessionStorage.token
						},
						success: function(data) {
							if(localStorage.userRemember == "false") {
								localStorage.removeItem("userCode");
							}
							location.href = sessionStorage.loginUrl;
							sessionStorage.clear();
						}
					});
				}, false, self);
			}
		},
		returnLogin:function(){
			rootOrgSet.dialogVisibleLogin = false;
		}
	}
	
});


//初始化
function Begin() {
	//面包屑
	new Vue().$mount('#crumbs');
	//左菜单滚动
	var oTop = $(".vany_authority").offset().top + 14;
	var sTop = 0;
	$(".vany_authority").scroll(function() {
		sTop = $(this).scrollTop();
		if(sTop >= oTop) {
			$(".conRight>div").css({
				"position": "fixed",
				"top": "60px",
				"right": "38px"
			});
		} else {
			$(".conRight>div").css({
				"position": "absolute",
				"top": "10px",
				"right": "10px"
			});
		}
	});

	sessionStorage.Jurisdiction = ""
}